<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
          <h3>以下侦听obj</h3>
          <button @click="obj.name = 'rose'">修改obj.name</button>
          <button @click="obj.age = 19">修改obj.age</button>
          <button @click="obj.pet.age = 2">修改obj.pet.age</button>
          <p>{{ obj }}</p>
    </div>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data () {
          return {
            obj: {
                name: 'jack',
                age: 16,
                pet: {
                  nickname: '汤姆',
                  age: 1
                }
            }
          }
        },
        watch: {
            // 我希望将来，obj的任意属性改变都能侦听到
            // 就要用深度侦听
            obj: {
              // 开启深度侦听
              deep: true,
              // 当obj里有任意属性发生变化，都会调用handler
              handler () {
                console.log('obj有属性改变了')
              },
              // 要不要初始化调用一次
              // 简单来说就是页面一打开就会立即调用一次handler
              immediate: true
            }
        }
      })
    </script>
  </body>
</html>